function isTrue(val)
{
	var v = Object.toJSON(val);


	try
	{
		return (val==true 
			|| ("number"==typeof(val) && 0!=val) 
			|| ("string"==typeof(val) && ""!=val  && "0"!=val && "off"!=val && "no"!=val) 
			|| ("object"==typeof(val) && null!=val && {}!=val && []!=val && "[]"!=v) 
			);
	}
	finally
	{
		v = null;
	}

}

function intVal(v)
{
	v = parseInt(v);

	if (isNaN(v))
	{
		v = 0;
	}

	return v;
}

function addSlashes( str )
{
    // http://kevin.vanzonneveld.net
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ates Goral (http://magnetiq.com)
    // +   improved by: marrtins
    // +   improved by: Nate
    // +   improved by: Onno Marsman
    // *     example 1: addslashes("kevin's birthday");
    // *     returns 1: 'kevin\'s birthday'
 
    return (str+'').replace(/([\\"'])/g, "\\$1").replace(/\0/g, "\\0");
}

function stripSlashes( str ) {
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: Ates Goral (http://magnetiq.com)
    // +      fixed by: Mick@el
    // +   improved by: marrtins
    // +   bugfixed by: Onno Marsman
    // +   improved by: rezna
    // +   input by: Rick Waldron
    // +   reimplemented by: Brett Zamir (http://brett-zamir.me)
    // *     example 1: stripslashes('Kevin\'s code');
    // *     returns 1: "Kevin's code"
    // *     example 2: stripslashes('Kevin\\\'s code');
    // *     returns 2: "Kevin\'s code"
    return (str+'').replace(/\\(.?)/g, function (s, n1) {
        switch(n1) {
            case '\\':
                return '\\';
            case '0':
                return '\0';
            case '':
                return '';
            default:
                return n1;
        }
    });
}

function isSet(o)
{
	return 'undefined' != typeof(o) ? true : false;
}


function pause(numberMillis)
{
	var now = new Date();
	var exitTime = now.getTime() + numberMillis;
	while (true)
	{
		now = new Date();
		if (now.getTime() > exitTime)
		{
			return;
		}
	}
}


function  request(name)
{
	var  reg = new RegExp( "(^|&)"+ name +"=([^&]*)(&|$)" );
	var r = window .location.search. substr(1).match (reg);
	reg = null;
	if (r!= null) return decodeURIComponent(r [2]); return null;
}


function getSwf(movieName)
{
    if (navigator.appName.indexOf("Microsoft") != -1)
	{
        return window[movieName];
    }
    else
	{
        return document[movieName];
    }
}



function getPageSize()
{
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY)
	{	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight)
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} 
	else if(document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if (document.body)
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
	{
		pageHeight = windowHeight;
	} 
	else
	{ 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
	{	
		pageWidth = windowWidth;
	} 
	else
	{
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	xScroll = yScroll = pageWidth = pageHeight = windowWidth = windowHeight =null;
	return arrayPageSize;
}




/**
 *	清除一下个拉框中的选项
 */
function clearOption(obj)
{
	obj.options.length =0;
	return true;

	var	l =	obj.options.length;

	for	(i=0;	i<l; i++)
	{
		obj.options.remove(0); 
	}
}

/**
 * 填充一下下拉框中的选项,data的格式为
 * 		var	data={
 * 			0:{v:'101', t:'天富', s:true},
 * 			1:{v:'102', t:'富民'}
 * 			}
 */
function addOptions(obj, data, v, type)
{
	var	rows = data;
	var len = rows.length;

	for	(i=0; i<len; i++)
	{
		var l = obj.options.length;
		obj.options[l]	= new Option(rows[i]['t'], rows[i]['v']);
	}

	if (isSet(v))
	{
		obj.value = v;
	}
	return true;
}

/**
 *添加一个option
 */
function addOption(obj, t, v)
{
	obj.options[obj.options.length]	= new Option(t, v);
}

/**
 * 下拉框中的数据更改时，把下拉框中的文本赋给另一控件
 */
function doSelectChange(objSel, objSetName)
{
	if(arguments.length > 2)
	{
		return arguments[2](objSel, objSetName);
	}

	if (isTrue(objSel.value))
	{
		var	t	=objSel.options[objSel.selectedIndex].text ;
	}
	else
	{
		t = '';
	}

	$(objSetName).value	= t ;
	
}



function resizeBodyText (size, id)
{
	var  nW  = $(size).offsetWidth;
	mod  = nW;

	// 40 seems to work well, but adjust this value for yourself.
	mod = Math . round(mod /50);

	var obj =  $(id);

	//limit how small the typeface can get
	if ( mod < 9 ) mod  = 9;

	obj. style.fontSize  = mod +"px";
	obj. style.lineHeight  = (mod *1.3)+"px" ;

}

function resizeColumn (nH, nW, id)
{
	// bug in IE 6 with the window height, only using width for now
	var mod  = (nW <  nH) ?  nW : nH ;
	mod  = nW;

	// this controls the level of the scale
	var multi  = 50;

	// sloppy math in here, i'm tired
	mod =  Math.round(mod/ multi );
	mod =  mod* multi;

	var col = $(id);
	//	col.style.width = (mod /2.3 ) + "px";
	//	col.style.left  =  i*(mod/2.3 ) + "px";
	//	resizeBodyText (size, id)
	col.style.fontSize = ( mod/multi) + "px" ;
	col.style.lineHeight = ((mod/multi) * 1.3) + "px" ;

	imgs = col.getElementsByTagName("img")
	for (var  x = 0; x  < imgs.length;  x++)
	{
		imgs[x].style.width =(mod/2.3)+ "px" ;
		//imgs[x].style.width =(mod/2.6)+ "px" ;
		//imgs[x].style.margin =(( mod/2.3)-( mod/ 2.6))/2.3 +"px" ;
	}   
}

function  resize(size, id)
{
	//resizeBodyText(size, id);
	var nH  =  $(size).offsetHeight - 80;

	// get window width
	var nW  = $(size).offsetWidth ;

	resizeColumn(nH, nW, id);
}


function keyDigits(ev)
{
	var elt = Event.element(ev);
		elt.value = formatDigits(elt.value);
}

function formatDigits(v)
{
		return v.replace(/[^\d]/g, '');
}


//读取cookie：
function readCookie(name) 
{ 
    var cookieValue = ""; 
    var search = name + "="; 
    if(document.cookie.length > 0) 
    { 
        offset = document.cookie.indexOf(search); 
        if (offset != -1) 
        { 
            offset += search.length; 
            end = document.cookie.indexOf(";", offset);

            if (end == -1)
            {
                end = document.cookie.length;
            }

            cookieValue = decodeURIComponent(document.cookie.substring(offset, end)) 
        } 
    } 
    return cookieValue; 
}


//写入cookie：
function writeCookie(name, value, hours) 
{ 
    var expire = ""; 
    if(hours != null) 
    { 
        expire = new Date((new Date()).getTime() + hours * 3600000); 
        expire = "; expires=" + expire.toGMTString(); 
    } 
    document.cookie = name + "=" + encodeURIComponent(value) + expire; 
} 


String.prototype.trim = function()
{
	return this.replace(/(^\s*)|(\s*$)/g, "");
}


function setCookie(name, value, hours, path, domain) 
{ 
	var expire = ""; 
	if(hours != null) 
	{ 
		expire = new Date((new Date()).getTime() + hours * 3600000); 
		expire = "; expires=" + expire.toGMTString(); 
	} 

	document.cookie = name + "=" + encodeURIComponent(value) + expire + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : ""); 
} 


Date.prototype.toStr = function() {
  return '' + this.getFullYear() + '-' +
    (this.getMonth() + 1).toPaddedString(2) + '-' +
    this.getDate().toPaddedString(2) + ' ' +
    this.getHours().toPaddedString(2) + ':' +
    this.getMinutes().toPaddedString(2) + ':' +
    this.getSeconds().toPaddedString(2) + '';
};

Date.prototype.toShortStr = function() {
  return '' + (this.getFullYear() + '').substr(2, 2) + '-' +
    (this.getMonth() + 1).toPaddedString(2) + '-' +
    this.getDate().toPaddedString(2) + ' ' +
    this.getHours().toPaddedString(2) + ':' +
    this.getMinutes().toPaddedString(2) + ':' +
    this.getSeconds().toPaddedString(2) + '';
};

Date.prototype.toTimeStr = function() {
  return '' +
    this.getHours().toPaddedString(2) + ':' +
    this.getMinutes().toPaddedString(2) + ':' +
    this.getSeconds().toPaddedString(2) + '';
};